﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;

namespace PlayerSDK
{
    public static class PlayCtrl
    {
        [DllImport("PlayCtrl.dll")]
        public static extern bool PlayM4_GetPort(ref int Port);

        [DllImport("PlayCtrl.dll")]
        public static extern bool PlayM4_FreePort(int Port);

        public static readonly ushort STREAME_REALTIME = 0;
        public static readonly ushort STREAME_FILE = 1;

        [DllImport("PlayCtrl.dll")]
        public static extern bool PlayM4_SetStreamOpenMode(int nPort, ushort nMode);

        [DllImport("PlayCtrl.dll")]
        public static extern bool PlayM4_OpenStream(int nPort, IntPtr pFileHeadBuf, uint nSize, uint nBufPoolSize);

        [DllImport("PlayCtrl.dll")]
        public static extern bool PlayM4_GetPictureSize(int nPort, out int pWidth, out int pHeight);

        [DllImport("PlayCtrl.dll")]
        public static extern bool PlayM4_SetDecCBStream(int nPort, ushort nStream);

        public struct FRAME_INFO
        {
            /// 画面宽，单位像素。如果是音频数据则为0
            public int nWidth;
            /// 画面高。如果是音频数据则为0
            public int nHeight;
            /// 时标信息，单位毫秒。
            public int nStamp;
            /// 数据类型，T_AUDIO16，T_RGB32， T_YV12
            public int nType;
            /// 编码时产生的图像帧率。
            public int nFrameRate;
        }

        public delegate void DecCBFun(int nPort, IntPtr pBuf, int nSize, ref FRAME_INFO pFrameInfo, int nReserved1, int nReserved2);

        [DllImport("PlayCtrl.dll")]
        public static extern bool PlayM4_SetDecCallBack(int nPort, DecCBFun dcbf);

        [DllImport("PlayCtrl.dll")]
        public static extern bool PlayM4_Play(int nPort, IntPtr hWnd);

        [DllImport("PlayCtrl.dll")]
        public static extern bool PlayM4_InputData(int nPort, IntPtr pBuf, uint nSize);

        [DllImport("PlayCtrl.dll")]
        public static extern bool PlayM4_Stop(int nPort);

        [DllImport("PlayCtrl.dll")]
        public static extern bool PlayM4_CloseStream(int nPort);

        [DllImport("PlayCtrl.dll")]
        public static extern bool PlayM4_OpenFile(int nPort, string sFileName);

        [DllImport("PlayCtrl.dll")]
        public static extern bool PlayM4_CloseFile(int nPort);

        [DllImport("PlayCtrl.dll")]
        public static extern bool PlayM4_Pause(int nPort, bool nPause);

        [DllImport("PlayCtrl.dll")]
        public static extern bool PlayM4_Fast(int nPort);

        [DllImport("PlayCtrl.dll")]
        public static extern bool PlayM4_Slow(int nPort);

        [DllImport("PlayCtrl.dll")]
        public static extern bool PlayM4_SetPlayPos(int nPort, float fRelativePos);

        [DllImport("PlayCtrl.dll")]
        public static extern float PlayM4_GetPlayPos(int nPort);

        [DllImport("PlayCtrl.dll")]
        public static extern bool PlayM4_OneByOne(int nPort);

        [DllImport("PlayCtrl.dll")]
        public static extern int PlayM4_GetFileTotalFrames(int nPort);

        [DllImport("PlayCtrl.dll")]
        public static extern uint PlayM4_GetCurrentFrameRate(int nPort);
      
        [DllImport("PlayCtrl.dll")]
        public static extern bool PlayM4_OneByOneBack(int nPort);

        [DllImport("PlayCtrl.dll")]
        public static extern int PlayM4_GetFileTime(int nPort);

        [DllImport("PlayCtrl.dll")]
        public static extern uint PlayM4_GetPlayedTimeEx(int nPort);

        [DllImport("PlayCtrl.dll")]
        public static extern bool PlayM4_SetCurrentFrameNum(int nPort, int nFrameNum);

        [DllImport("PlayCtrl.dll")]
        public static extern bool PlayM4_SetPlayedTimeEx(int nPort, int nTime);

        [DllImport("PlayCtrol.dll")]
        public static extern uint PlayM4_GetFileHeadLength();

        [DllImport("PlayCtrl.dll")]
        public static extern uint PlayM4_GetCurrentFrameNum(int nPort);

        public delegate void FileRefDone(int nPort, ushort nUser);
        [DllImport("PlayCtrl.dll")]
        public static extern bool PlayM4_SetFileRefCallBack(int nPort, FileRefDone frd, ushort nUser);

        [DllImport("PlayCtrl.dll")]
        public static extern bool PlayM4_GetRefValue(int nPort, IntPtr pBuffer, ref ushort pSize);

        [DllImport("PlayCtrl.dll")]
        public static extern bool PlayM4_SetRefValue(int nPort, IntPtr pBuffer, ushort nSize);

        [DllImport("PlayCtrl.dll")]
        public static extern bool PlayM4_SetFileEndMsg(int nPort, IntPtr hWnd, uint nMsg);

        public delegate void DrawFun(int nPort, IntPtr hDc, int nUser);
        [DllImport("PlayCtrl.dll")]
        public static extern bool PlayM4_RigisterDrawFun(int nPort, DrawFun df, int nUser);
    }
}
